package ensemble.samples.custom.sqlformat.javafx.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javafx.application.Platform;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

/**
 * @author duanxq
 * @date 2022/2/24
 */
public class AppContext {


    private static TextArea inputTextArea;
    private static BorderPane rootLayout;
    private static Stage stage;

    private final  static ExecutorService executorService = new ThreadPoolExecutor(2, 2, 1000,
        TimeUnit.SECONDS,
        new ArrayBlockingQueue<>(1000));

    public static ExecutorService getExecutorService() {
        return executorService;
    }

    public static String getContentFromInput() {
        return inputTextArea.getText();
    }
    public static void contentOutput(String s) {
        Platform.runLater(() ->{
            inputTextArea.setText(s);
        });
    }
    public static void contentOutAppend(String s) {
        Platform.runLater(() ->{
            inputTextArea.appendText("\n" + s);
        });
    }

    public static TextArea getInputTextArea() {
        return inputTextArea;
    }

    public static void setInputTextArea(TextArea inputTextArea) {
        if (AppContext.inputTextArea == null) {
            AppContext.inputTextArea = inputTextArea;
        }
    }

    public static BorderPane getRootLayout() {
        return rootLayout;
    }

    public static void setRootLayout(BorderPane rootLayout) {
        AppContext.rootLayout = rootLayout;
    }

    public static Stage getStage() {
        return stage;
    }

    public static void setStage(Stage stage) {
        AppContext.stage = stage;
    }
}
